
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/pintuer.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/admin.css">
    <script src="<%=request.getContextPath()%>/js/jquery.js"></script>
    <script src="<%=request.getContextPath()%>/js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加请假单</strong></div>
    <div class="body-content">
        <!--注意action值的正确设置-->
        <form method="post" class="form-x" action="LeaveServlet?action=add">
            <div class="form-group">
                <div class="label">
                    <label>请假单号：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" value="" name="leaveID" id="leaveID" data-validate="required:请输入请假单号" readonly/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>请假课程：</label>
                </div>
                <div class="field">
                    <select class="input w50" name="courseID" data-validate="required:请选择请假课程">
                        <c:forEach var="course" items="${requestScope.courseList}">
                            <option value="${course.courseID}">${course.courseID} -- ${course.courseName}</option>
                        </c:forEach>
                    </select>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>请假事由：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" value="" name="reason" data-validate="required:请输入请假事由" />
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>请假天数：</label>
                </div>
                <div class="field">
                    <input type="number" class="input w50" value="" name="daynum" data-validate="required:请输入请假天数" />
                    <div class="tips"></div>
                </div>
            </div>


            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    /// 在页面加载时生成随机值并填充到leaveID输入框中
    window.onload = function() {
        var randomLeaveID = generateRandomLeaveID();
        document.getElementById("leaveID").value = randomLeaveID;
    };

    /// 生成随机的leaveID
    function generateRandomLeaveID() {
        var currentDate = new Date();
        var year = currentDate.getFullYear();
        var month = padZero(currentDate.getMonth() + 1); // 月份从0开始，所以需要加1
        var day = padZero(currentDate.getDate());
        var hours = padZero(currentDate.getHours());
        var minutes = padZero(currentDate.getMinutes());
        var seconds = padZero(currentDate.getSeconds());
        var randomDigits = generateRandomDigits(3);

        return year + month + day + hours + minutes + seconds + randomDigits;
    }

    /// 生成指定位数的随机数字
    function generateRandomDigits(numDigits) {
        var maxNumber = Math.pow(10, numDigits) - 1;
        var randomNum = Math.floor(Math.random() * maxNumber);
        return padZero(randomNum, numDigits);
    }

    /// 补齐数字前导零，使其达到指定的位数
    function padZero(number, numDigits) {
        var numberString = String(number);
        while (numberString.length < numDigits) {
            numberString = "0" + numberString;
        }
        return numberString;
    }

</script>
